import json
import os
from openpyxl import load_workbook
import pandas as pd
from tqdm import tqdm
from basic_component_related_management.models import *

# 创建一个superadmin，密码是superadmin1234
user_entity = User.objects.filter(user_account="superadmin").first()
if user_entity is None:
    user_entity = User.objects.create(
        user_account="superadmin",
        user_name="superadmin",
        password="C6IDQGUT42vVUX0neDCF2TB2kD42tBWwp4AGqp3DenmkTYI9urFbhJomuOMcI25De98AjQJPBT07AUW5oQdYeHfeQKr/uhR6OABnKu+/uof5viBguKPdDqkc/znPMjADdt66dxVi/yeur8EahDaUCvhssdB4HkJLxteCLGlEDZ/AJe1BiTBCgyN+7ZLCEjxXD4lKbI5mT9oWEQ+Pd1rE7fY/jmuDh6Nnz2YO7/0WvQA39KESBVzrVQ5bmEVSnUNkQqfzR8DkylHQ54swmNGXFog9xd7q0gjd2VrsBfE6qD4y+iJThQlALLh1f9QdVthAcuepLUKW+PI/mmyllQTufw=="
    )




def init_phase_dataV1():
    data_file = "files/phase_dataV1/0. 数据字典-相态列表(20241220R1)（初始化）.xlsx"
    sheet_name1 = "0-SEIDB相态列表"
    df1 = pd.read_excel(data_file, sheet_name=sheet_name1, dtype=str)
    df1 = df1.fillna("")
    df1 = df1.iloc[2:, :]
    for index, row in tqdm(df1.iterrows(), desc="相态列表"):
        short_name = row.iloc[1]
        name = row.iloc[2]
        name_en = row.iloc[3]
        description = row.iloc[4]
        description_en = row.iloc[5]
        phase_type = row.iloc[6]
        comment = row.iloc[7]
        comment += "\n" + "缩写:" + short_name
        comment += "\n" + "类型:" + phase_type
        Phase.objects.create(
            name = name,
            name_en = name_en,
            is_pure_used = True,
            is_binary_used = True,
            is_ternary_used = True,
            is_reaction_used = True,
            is_complex_used = True,
            description = description,
            description_en = description_en,
            comment = comment,
            create_person = user_entity,
            modify_person = user_entity,
        )
            
        